-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(resolve): exclude empty optional arguments from params #2434
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for vue-router canceled.
|
packages/router/src/matcher/index.ts
Outdated
@@ -310,6 +310,12 @@ export function createRouterMatcher( | |||
// we know the matcher works because we tested the regexp | |||
params = matcher.parse(path)! | |||
name = matcher.record.name | |||
|
|||
matcher?.keys.forEach(key => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the ?.
be changed to .
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skirtles-code
Thank you for your comment.
Oh, it was a remnant from writing outside of this block.
Fixed!
66f824f
I was wondering about some other edge cases. I'm not sure whether these necessarily impact this PR, but I thought they were worth considered before it's merged. I put together this Playground to demonstrate: These are are
All of them lead to the same path. Clicking around between them, it seems that 2, 3 and 4 are considered equivalent, which makes sense. It's 5 that I found most interesting. It seems to behave like it's a child of 2, 3 and 4. I also tried with Not sure if that's intentional or not, but it doesn't seem to match what's described at https://router.vuejs.org/guide/essentials/active-links.html. I wrote that page, so I may be to blame for describing these classes incorrectly. It seems that there's some special handling for optional |
fix #2419
Removed if optional parameter is empty
Now the param will match if :to is string and if it is object
In the case of string path, it should not be an empty string parameter(Right?)
, so I thought there would be no problem with excluding it.
However, this may be a breaking change if you have users who were using this
In addition, I added a router-link to Playgound to check the operation.